Skip to content

Fix CryptoBase.SpeedTest compilation after System.CommandLine v2 upgrade#87

Closed
Copilot wants to merge 2 commits intorenovate/system.commandline-2.xfrom
copilot/fix-cryptobase-speedtest-compile-error
Closed

Fix CryptoBase.SpeedTest compilation after System.CommandLine v2 upgrade#87
Copilot wants to merge 2 commits intorenovate/system.commandline-2.xfrom
copilot/fix-cryptobase-speedtest-compile-error

Conversation

Copy link
Contributor

Copilot AI commented Oct 10, 2025

Problem

After upgrading the System.CommandLine package to version 2.0.0-rc.1.25451.107, the CryptoBase.SpeedTest project failed to compile with 9 errors. The v2 API introduced several breaking changes that required updates to the command-line argument and option configuration code.

Changes

Updated Program.cs to use the new System.CommandLine v2 API:

1. Argument and Option Constructors

Before:

Argument<string> methodsArgument = new(@"method(s)", () => CryptoList.All, @"Methods separated by commas.");
Option<double> secondsOption = new(@"--seconds", () => 3.0, @"Run benchmarks for num seconds.");

After:

Argument<string> methodsArgument = new(@"method(s)")
{
    Description = @"Methods separated by commas.",
    DefaultValueFactory = _ => CryptoList.All
};
Option<double> secondsOption = new(@"--seconds", [@"-s"])
{
    Description = @"Run benchmarks for num seconds.",
    DefaultValueFactory = _ => 3.0
};

2. Completions

Before:

methodsArgument.AddCompletions(CryptoList.All);
methodsArgument.AddCompletions(method);

After:

methodsArgument.CompletionSources.Add(new[] { CryptoList.All });
methodsArgument.CompletionSources.Add(CryptoList.Methods.ToArray());

3. Command Configuration

Before:

RootCommand cmd = [methodsArgument, secondsOption, bytesOption];

After:

RootCommand cmd = new(@"CryptoBase Speed Test");
cmd.Add(methodsArgument);
cmd.Add(secondsOption);
cmd.Add(bytesOption);

4. Action Handler and Invocation

Before:

cmd.SetHandler((methods, seconds, bytes) => { /* ... */ }, methodsArgument, secondsOption, bytesOption);
return cmd.Invoke(args);

After:

cmd.SetAction((parseResult) =>
{
    string methods = parseResult.GetValue(methodsArgument)!;
    double seconds = parseResult.GetValue(secondsOption);
    int bytes = parseResult.GetValue(bytesOption);
    /* ... */
});
return cmd.Parse(args).Invoke();

Verification

  • ✅ Solution builds successfully with no compilation errors
  • ✅ All 286 unit tests pass
  • ✅ Command-line help displays correctly with all completions
  • ✅ Individual crypto methods work: dotnet run -- aes-128-ctr --seconds 1
  • ✅ Multiple methods work: dotnet run -- aes-128-ctr,rc4 --seconds 1
  • ✅ "all" option works: dotnet run -- all --seconds 1
  • ✅ Command-line options function correctly: --seconds, --bytes, -s, -b

The changes maintain full backward compatibility with the existing command-line interface while adapting to the new System.CommandLine v2 API.

Original prompt

包升级后 CryptoBase.SpeedTest 编译应该会报错,修正错误


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: HMBSbige <19153265+HMBSbige@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix compilation error after package upgrade for CryptoBase.SpeedTest Fix CryptoBase.SpeedTest compilation after System.CommandLine v2 upgrade Oct 10, 2025
Copilot AI requested a review from HMBSbige October 10, 2025 10:17
@HMBSbige HMBSbige marked this pull request as ready for review October 10, 2025 11:02
@renovate renovate bot deleted the branch renovate/system.commandline-2.x October 10, 2025 13:59
@renovate renovate bot closed this Oct 10, 2025
@HMBSbige HMBSbige deleted the copilot/fix-cryptobase-speedtest-compile-error branch October 11, 2025 04:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants